package ui.timeline;

import javax.swing.JSlider;



public class OneThumbTimeLineSlider extends JSlider {

    /**
	 * 
	 */
	private static final long serialVersionUID = 8942286590518918775L;
	/**
     * Constructs a RangeSlider with default minimum and maximum values of 0
     * and 100.
     */
	public int trackHeight = 10;

	public long currentValue;
	
	private long beginTime;
	private long endTime;
	
    public OneThumbTimeLineSlider() {
        initSlider();
    }

    /**
     * Constructs a RangeSlider with the specified default minimum and maximum 
     * values.
     */
    public OneThumbTimeLineSlider(long beginTime, long endTime) {
        super(0, (int)(endTime-beginTime));
        
        this.beginTime = beginTime;
        this.setEndTime(endTime);

        this.setValue(0);
        
        initSlider();
    }
    
    public long getBeginTime()
    {
    	return this.beginTime;
    }
    public void setBeginTime(long value)
    {
    	this.beginTime = value;
    }

    /**
     * Initializes the slider by setting default properties.
     */
    private void initSlider() {
        setOrientation(HORIZONTAL);
    }

    /**
     * Overrides the superclass method to install the UI delegate to draw two
     * thumbs.
     */
    @Override
    public void updateUI() {
        setUI(new OneThumbTimeLineSliderUI(this));
        // Update UI for slider labels.  This must be called after updating the
        // UI of the slider.  Refer to JSlider.updateUI().
        updateLabelUIs();
    }


	public void repaintCurrentThumb()
	{
		this.updateUI();
	}

	public boolean isDragging()
	{
		return ((OneThumbTimeLineSliderUI)this.getUI()).currentDragging;
	}

	public long getEndTime() {
		return endTime;
	}

	public void setEndTime(long endTime) {
		this.endTime = endTime;
	}
	
	public void setCurrentValue(long value)
	{
		this.currentValue = value;
	}
	
	public long getCurrentValue()
	{
		return this.currentValue;
	}
	
	public void setRange(long beginTime, long endTime)
	{
		this.beginTime = beginTime;
		this.endTime = endTime;
		this.getModel().setRangeProperties(0, (int)(this.endTime - this.beginTime), 0, (int)(this.endTime - this.beginTime) , this.getValueIsAdjusting());
	}
}